const app = getApp()

Page({

  data: {
    info:{
      bank: {money:0, tobo_paid:0,point:0,coupon_save:0},
      num: {fans:0, store:0, vip: 0}
    },
    loading:true,
    list: [],
    page: 0,
  },

  param:{
    type: 0,
  },

  onShow: function (options) {
    app.loginState(()=>{
      this.getApi();
      this.getList();
    },true)
  },
  //获取会员数据
  getApi:function () {
    app.api().Get("api/v1/ais/user/analysis",(rel) => {
      if(200 == rel.code){
        this.setData({
          info:rel.data
        }) 
      }
		})
  },
  //下拉刷新
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    setTimeout(()=>{
      wx.hideNavigationBarLoading();
      wx.stopPullDownRefresh();
    },1500);
    this.setData({
      loading: true,
      page:0,
      list:[]
    });
    this.getList();
  },
  //上拉加载更多
  onReachBottom: function () {
    this.setData({
      loading: true,
    }); 
    this.getList();
  },
  /**
   * 点击切换
   */
  onChange(event) {
    this.setData({
      loading: true,
      page: 0,
      list: [],
    });
    this.param.type = event.detail.index;
    this.getList();
  },
  /**
   * 账单
   */
  getList: function () {
    if (this.data.loading) {
      var param = {
        page: this.data.page + 1,
        type: this.param.type
      }
      app.api().Get("api/v1/ais/user/bill",param,(result) => {
        if (result.code == 200) {
          var list = this.data.list;
          for (let i in result.data) {
            list.push(result.data[i]);
          }
          this.setData({
            list: list,
            page: param.page,
          });
        }
      })
      this.setData({
        loading: false,
      });
    }
  },
  //开通会员
  onUrl:function (e) {
    wx.navigateTo({
      url:e.currentTarget.dataset.url
    })
  }
})